﻿namespace NTLib.WPF.Selectors
{
    using Controls;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;

    /// <summary>
    /// s
    /// </summary>
    /// <seealso cref="NTLib.WPF.Selectors.MetaDataTemplateSelector" />
    public class PropertyInfoTypeDataTemplateSelector : MetaDataTemplateSelector
    {
        #region Methods

        /// <summary>
        /// Gets the key.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="container"></param>
        protected override string GetKey(object item, DependencyObject container)
        {
            if (item == null)
                return null;

            Type type = item.GetType();

            if (item is PropertyViewerItem)
            {
                PropertyViewerItem itm = item as PropertyViewerItem;
                if (!string.IsNullOrEmpty(itm.SpecialKey))
                    return itm.SpecialKey;
                type = itm.PropertyType;
            }

            if (item is PropertyInfo)
            {
                var info = item as PropertyInfo;
                type = info.PropertyType;
            }

            if (type.IsEnum)
                return "enum";
            return type.Name;
        }

        #endregion
    }
}
